package cn.jtool.dig.common.model;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum Commands implements Serializable {

    COMMON_RESPONSE(0x10, "通用应答"),
    HEARBEAT(0x11, "心跳"),
    FORWARD_LIST(0x12, "转发清单"),
    CREATE_SESSION(0x13, "创建链路"),
    CLOSE_SESSION(0x14, "断开链路"),
    AUTH(0x15, "认证"),
    DATA_TRANSPARENT(0x50, "发送数据");

    private Integer code;
    private String name;

    private static Map<Integer, Commands> commandsMap = Maps.newHashMap();
    static {
        Arrays.stream(values()).forEach(command -> {
            commandsMap.put(command.getCode(), command);
        });
    }

    public static Commands valueOfCode(int code){
        return commandsMap.get(code);
    }
}
